package com.bweab.service.impl;

import com.bweab.dao.api.DepositTbDaoInterface;
import com.bweab.dao.impl.DepositTbDaoImpl;
import com.bweab.pojo.DepositTb;
import com.bweab.service.api.DepositTbServiceInterface;
import com.bweab.util.PageList;

import java.util.List;

/**
 * 宿舍信息服务接口的实现
 *
 * */
public class DepositTbServiceInterfaceImpl implements DepositTbServiceInterface {

    DepositTbDaoInterface depositTbDao = new DepositTbDaoImpl();//调用dao


    @Override
    public int depositMonkey(int userid, int usermonkey, int dormitoryid) {
        //调用充值
        int row= depositTbDao.insertDeposit(userid,usermonkey,dormitoryid);
        //调用充值

        return row;
    }

    /**
     *
     * @param userId 用户id
     * @param dormitoryId 寝室id
     * @param userFee 用户费用
     * @return 返回结果 1为成功  0 为失败
     */
    @Override
    public int addDepositMonkey(int userId, int dormitoryId, int userFee) {

        //服务调用dao
        int rows= depositTbDao.insertDeposit(userId,userFee,dormitoryId);

        return rows;
    }


    /**
     * 根据用户id查询返回结果
     * @param depositId 用户id
     * @return 1成功 0失败
     */
    @Override
    public DepositTb getDepositById(int depositId) {
        //根据充值id 获取充值信息
        DepositTb depositInfo=depositTbDao.getDepositInfoById(depositId);
        return depositInfo;
    }

    /**
     * 该方法修改充值记录的
     *
     * @param dormitoryId 寝室id
     * @param userId      用户id
     * @param userFee     用户费用
     * @param depositId
     * @return 1成功 0失败
     */
    @Override
    public int alterDepositInfo(int dormitoryId, int userId, int userFee, int depositId) {
        int rows= depositTbDao.alterDepositInfo(dormitoryId,userId,userFee,depositId);
        return rows;
    }


    /**
     * 通过寝室id删除充值记录
     * @param dormitoryId 寝室id
     * @return 1成功 0失败
     */
    @Override
    public int deleteDepositByDormitoryId(int dormitoryId) {
        int rows=depositTbDao.deleteDepositByDorrmitoryId(dormitoryId);
        return rows;
    }


    /***
     * 通过充值记录id删除
     * @param depositId 充值记录id
     * @return 1成功 0 失败
     */
    @Override
    public int deleteDepositByDepositId(int depositId) {
        int rows=depositTbDao.deleteDepositByDepositId(depositId);
        return rows;
    }


    /**
     * 通过用户id删除充值记录
     *
     * @param userId 用户id
     * @return 1成功 0失败
     */
    @Override
    public int deleteDepositByUserId(int userId) {
        int rows=depositTbDao.deleteDepositByUserId(userId);
        return rows;
    }

    /**
     * 通过充值记录id获取充值信息
     * @param depositId 充值记录id
     * @return 返回的是Deposit集合
     */
    @Override
    public List<DepositTb> queryDepositInfoByUserId(int depositId) {
        List<DepositTb>  depositTbList=depositTbDao.queryDepositInfoByUserId(depositId);
        return depositTbList;
    }

    /**
     * 通过充值记录id获取集合
     * @param depositId 充值记录id
     * @param page      当前页
     * @param pageSize  limit 获取大小
     * @return
     */
    @Override
    public PageList queryDepositInfoByDepositId(int depositId, int page, int pageSize) {
        PageList depositPageList=new PageList();
        //服务层对dao的返回结果在进行处理

        //Dao层对这些进行判断
        List<DepositTb>  depositTbList=depositTbDao.queryDepositInfoByUserId(depositId,page,pageSize);
        if(depositTbList.size()>0){
            depositTbList.get(0);
            //设置页数
            depositPageList.setPageList(depositTbList);
        }
        return depositPageList;
    }
}
